package com.ltt.controller;

import com.ltt.common.UserThreadLocal;
import com.ltt.dao.pojo.CommentOne;
import com.ltt.dao.pojo.CommentTwo;
import com.ltt.dao.vo.CommentVo;
import com.ltt.dao.vo.Result;
import com.ltt.dao.vo.params.CommentOneParams;
import com.ltt.dao.vo.params.CommentTwoParams;
import com.ltt.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * @author ‘李天泰’
 * @version 1.0
 * @description: TODO
 * @date 2023/5/1 22:03
 */
@Api(tags = "评论模块")
@RestController
@RequestMapping("comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @ApiOperation("获取所有评论")
    @PostMapping("getAllComment")
    private Result getAllComment(int blog_id){
        List<CommentVo> allComment = commentService.getAllComment(blog_id);
        return Result.successWithData(allComment);
    }

    @ApiOperation("插入一级评论")
    @PostMapping("insertCommentOne")
    private Result insertCommentOne(@RequestBody CommentOneParams commentOneParams){
        CommentOne commentOne = new CommentOne();
        BeanUtils.copyProperties(commentOneParams,commentOne);
        commentOne.setId(UUID.randomUUID().toString());
        commentOne.setUserId(UserThreadLocal.get().getOpenid());
        commentService.insertCommentOne(commentOne);
        return Result.successWithoutData();
    }

    @ApiOperation("插入二级评论")
    @PostMapping("insertCommentTwo")
    private Result insertCommentTwo(@RequestBody CommentTwoParams commentTwoParams){
        CommentTwo commentTwo = new CommentTwo();
        BeanUtils.copyProperties(commentTwoParams,commentTwo);
        commentTwo.setId(UUID.randomUUID().toString());
        commentTwo.setUserId(UserThreadLocal.get().getOpenid());
        commentService.insertCommentTwo(commentTwo);
        return Result.successWithoutData();
    }
}
